package com.processmining.filter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import com.processmining.entity.User;

public class AuthFilter implements HandlerInterceptor{
	private static final String[] IGNORE_URI={"index.html"};
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object obj) throws Exception {
		//HttpSession sesson=req.getSession();
		//User u=(User)session.getAttribute("user");
		String url=req.getRequestURL().toString();
		boolean noAuthRequired=false;
		for(String s:IGNORE_URI){
			if(url.contains(s)){
				noAuthRequired=true;
				return noAuthRequired;
			}
		}
		return false;
	}
}
